const debug = process.env.NODE_ENV !== 'production';

module.exports = {
  configureWebpack: config => {
    if (debug) {
      console.log('设置source-map');
      config.devtool = 'source-map';
    }
  },
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:3001',
        bypass: function(req, res) {
          if (req.headers.accept.indexOf('html') !== -1) {
            return '/index.html';
          } else if (process.env.MOCK !== 'none') {
            const name = req.path.split('/api/')[1];
            const body = require(`./mock/${name}`);
            delete require.cache[require.resolve(`./mock/${name}`)];
            return res.send(body);
          }
          return null;
        }
      }
    }
  }
};
